package LeetCode;

public class LC_495_TeemoAttacking {

    public static void main(String[] args) {

    }

    public class Solution {
        public int findPoisonedDuration(int[] timeSeries, int duration) {
            if (timeSeries == null || timeSeries.length == 0 || duration <= 0) return 0;
            int res = 0, start = timeSeries[0], end = timeSeries[0] + duration;
            for (int i = 1; i < timeSeries.length; i++) {
                if (timeSeries[i] > end) {
                    res += end - start;
                    start = timeSeries[i];
                }
                end = timeSeries[i] + duration;
            }
            res += end - start;
            return res;
        }

    }
}